package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.EquCoolingvestEntity;
import io.renren.modules.sys.service.EquCoolingvestService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-09-02 15:02:54
 */
@RestController
@RequestMapping("sys/equcoolingvest")
public class EquCoolingvestController {
    @Autowired
    private EquCoolingvestService equCoolingvestService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:equcoolingvest:list")
    public R list(@RequestParam Map<String, Object> params){
        //System.out.println("@@@@"+params.toString());
        if(params.size() == 0) {
            List<Map<String, Object>> equList = equCoolingvestService.selectEqu();
            PageUtils page = new PageUtils(equList,equList.size(),1,0);
            return R.ok().put("page", page);
        }
        else {
            PageUtils page = equCoolingvestService.queryPage(params);
            return R.ok().put("page", page);
        }
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:equcoolingvest:info")
    public R info(@PathVariable("id") String id){
        EquCoolingvestEntity equCoolingvest = equCoolingvestService.selectById(id);

        return R.ok().put("equCoolingvest", equCoolingvest);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:equcoolingvest:save")
    public R save(@RequestBody EquCoolingvestEntity equCoolingvest){
        equCoolingvest.setId(UUID.randomUUID().toString());
        equCoolingvestService.insert(equCoolingvest);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:equcoolingvest:update")
    public R update(@RequestBody EquCoolingvestEntity equCoolingvest){
        ValidatorUtils.validateEntity(equCoolingvest);
        equCoolingvestService.updateAllColumnById(equCoolingvest);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:equcoolingvest:delete")
    public R delete(@RequestBody String[] ids){
        equCoolingvestService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
